package com.queen.testretrofitrxjava.ui.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.queen.testretrofitrxjava.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by liukun on 16/3/12.
 */
public class MainFragment extends Fragment {

    public static final String TAG = MainFragment.class.getSimpleName();

    @Bind(R.id.main_retrofit_demo_TV)
    TextView mainRetrofitDemoTV;
    @Bind(R.id.main_top_movie_TV)
    TextView mainTopMovieTV;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v  = inflater.inflate(R.layout.fragment_main, container, false);
        ButterKnife.bind(this, v);
        return v;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.main_retrofit_demo_TV, R.id.main_top_movie_TV})
    public void onClick(View view) {
        Fragment targetFragment = null;
        String tag = "";

        switch (view.getId()) {
            case R.id.main_retrofit_demo_TV:
                targetFragment = new RetrofitRxjavaFragment();
                tag = RetrofitRxjavaFragment.TAG;
                break;
            case R.id.main_top_movie_TV:
                targetFragment = new TopMovieFragment();
                tag = TopMovieFragment.TAG;
                break;

        }

        getFragmentManager()
                .beginTransaction()
                .replace(R.id.activity_main_RL, targetFragment, tag)
                .addToBackStack(MainFragment.TAG)
                .commit();
    }
}

